package com.yuji.aacar.widgets.loading;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Rect;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.yuji.aacar.R;
import com.yuji.aacar.widgets.autolayout.utils.AutoUtils;



/**
 * <li>Package: {@link WLoadingDialog}
 * <li>Author: cyh
 * <li>Date: 2017/4/14 15:21
 * <li>Discription: APP请求加载加载对框
 */
public class WLoadingDialog extends Dialog implements DialogInterface.OnDismissListener{

    public WLoadingDialog(Context context){
        super(context, R.style.customDailogStyle);
        setContentView(R.layout.widgets_dialog_loading);
        setCanceledOnTouchOutside(false);
        setOnDismissListener(this);

        Window mWindow = this.getWindow();
        mWindow.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
        mWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

        Rect rect = new Rect();
        ((Activity)context).getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
        int height = rect.height() - AutoUtils.getPercentHeightSize(140);
        mWindow.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, height);
    }

    @Override
    public void onDismiss(DialogInterface dialogInterface) {
        setCancelable(false);
    }

}
